<?php
/**
 * Created by PhpStorm.
 * User: yellow
 * Date: 2019/5/29
 * Time: 12:44
 */

namespace app\admin\controller;


use app\admin\logic\BusBusinessLogic;
use app\admin\logic\BusSkdLogic;
use app\admin\logic\CityLogic;
use think\facade\Request;

class BusSkd extends Base
{

    private $busSkdLogic;

    public function __construct()
    {
        parent::__construct();
        $this->busSkdLogic = new BusSkdLogic();
    }

    public function index(){
        $businessLogic = new BusBusinessLogic();
        $businessList = $businessLogic->getAllBusiness();
        $this->assign('business', $businessList['data']);
        return $this->fetch();
    }

    /**
     *
     */
    public function ajaxIndex(){
       $tempWhere = Request::post('');
       $skdList = $this->busSkdLogic->busSkdList($tempWhere, self::$nowPage);
       return json($skdList);
    }

    public function add(){
        $act = 'add';
        $id = Request::get('id');
        $html = "add";
        if ($id){
            $act = 'edit';
            $info = $this->busSkdLogic->info($id);
            $this->assign('info', $info['data']);
            $html = "edit";
        }
        $businessLogic = new BusBusinessLogic();
        $businessList = $businessLogic->getAllBusiness();
        $cityList = CityLogic::cityList();
        $this->assign('city_list', $cityList['data']);
        $this->assign('business', $businessList['data']);
        $this->assign('act', $act);
        return $this->fetch($html);
    }

    public function dateAdd(){
        $dateRange = Request::post('date_range');
        $dateRange = explode(' - ', $dateRange);
        $dateDays = (strtotime($dateRange[1]) - strtotime($dateRange[0])) / (24*60*60);
        $cityList = CityLogic::cityList();
        $this->assign('city_list', $cityList['data']);
        $this->assign('date_range', strtotime($dateRange[0]));
        $this->assign('date_days', ($dateDays));
        return json($this->fetch('date_add'));
    }

    /**
     * 处理逻辑
     * @return \think\response\Json
     */
    public function handle(){
        $data = Request::param('');
        $res = $this->busSkdLogic->handle($data);
        return json($res);
    }

}